package xpn.platform.modules.todo.todolink;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;
import org.springframework.data.rest.core.config.Projection;
import xpn.platform.common.repository.XpnRepository;
import xpn.platform.modules.todo.common.TodoStateEnum;

import java.util.Date;

/**
 * 待办Dao
 *
 * @author zyk
 */
@RepositoryRestResource(path = "todo_link", excerptProjection = TodoLinkProjection.class)
public interface TodoLinkDAO extends XpnRepository<TodoLink, Long> {



    /**
     * 根据业务Id
     *
     * @param taskId
     * @return
     */
    @RestResource(exported = false)
    TodoLink findByTaskId(@Param("taskId") String taskId);

    /**
     * 根据用户ID查询待办数量
     *
     * @param userId
     * @return
     */
    @Query(value = "select count(o.id) from TodoLink o  where o.sendeeId=:sendeeId")
    Long getTodoCountByUserId(@Param("sendeeId") String sendeeId);
}

@Projection(name = "default", types = {TodoLink.class})
interface TodoLinkProjection {



    Long getId();

    String getTaskId();

    String getLinkUrl();

    String getType();

    String getSubject();

    String getCreatorId();

    String getCreatorName();

    String getCreatorOrgName();

    String getSenderId();

    String getSenderName();

    String getSendeeId();

    String getCategory();

    Date getSentTime();

    String getEmergency();

    TodoStateEnum getState();

    Date getTimelimit();
}
